package com.biz.primus.ms.product.api;

import com.biz.primus.base.vo.commodity.ProductIdxIdentityVo;
import com.biz.primus.base.vo.search.ProductIdxVo;
import com.biz.primus.ms.product.dao.redis.RedisLockRedisDao;
import com.biz.primus.ms.product.service.ProductIdxService;
import com.biz.primus.search.vo.search.ProductIdxReqVo;
import com.biz.primus.search.vo.search.ProductIdxRespVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangnan
 * @Description:商品索引接口
 */
@Api("商品索引接口")
@RestController
@RequestMapping("soa/productIdxService")
public class ProductIdxApiController {

    private final ProductIdxService productIdxService;

    private final RedisLockRedisDao redisLockRedisDao;

    public ProductIdxApiController(ProductIdxService productIdxService, RedisLockRedisDao redisLockRedisDao) {
        this.productIdxService = productIdxService;
        this.redisLockRedisDao = redisLockRedisDao;
    }


    @ApiOperation("索引商品信息")
    @PostMapping("getSearchIndices")
    List<ProductIdxVo> getSearchIndices(@RequestBody List<ProductIdxIdentityVo> identityVos){
        return productIdxService.getSearchIndices(identityVos);
    }

    @ApiOperation("商品索引信息")
    @PostMapping("getSearchIdx")
    ProductIdxVo getSearchIdx(@RequestBody ProductIdxIdentityVo productIdxIdentityVo){
        return productIdxService.getSearchIdx(productIdxIdentityVo);
    }

    @ApiOperation("批量获取索引")
    @PostMapping("getProductIndices")
    ProductIdxRespVo getProductIndices(@RequestBody ProductIdxReqVo req){
        return productIdxService.getProductIndices(req);
    }

    @GetMapping("tryLockMakeAllTypeBProductIndex")
    Boolean tryLockMakeAllTypeBProductIndex(){
        return redisLockRedisDao.tryLock("typeB",60);
    }

    @GetMapping("unLockMakeAllTypeBProductIndex")
    void unLockMakeAllTypeBProductIndex(){
        redisLockRedisDao.unLock("typeB");
    }

}
